package com.service;
import java.util.List;
import com.model.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
import com.mapper.CourseMapper;
@Service
public class CourseServiceImpl implements CourseService
{
        
        @Autowired
	private CourseMapper courseMapper;


	public List<Course> queryCourseList(Course course) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		if(course!=null){
			map.put("tid", course.getTid());
			map.put("name", course.getName());
			map.put("jgid", course.getJgid());
			map.put("bname", course.getBname());
		}
		
		List<Course> getCourse = courseMapper.query(map);
		return getCourse;
	}
	public List<Course> report(Course course) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		if(course!=null){
			map.put("tid", course.getTid());
		 
		}
		
		List<Course> getCourse = courseMapper.report(map);
		return getCourse;
	}

	
	public int insertCourse(Course course) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		if(course!=null){
			map.put("tid", course.getTid());
			map.put("name", course.getName());
			map.put("jgid", course.getJgid());
			map.put("bname", course.getBname());
			map.put("xq", course.getXq());
		}
		List<Course> courselist= courseMapper.queryCourseByAll(map);
		if(courselist.size()>0){
			return 0;
		}else{
			return courseMapper.insertCourse(course);
		}
		
	}

	public int deleteCourse(int id) throws Exception {
		return courseMapper.deleteCourse(id);
	}

	public int updateCourse(Course course) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		if(course!=null){
			map.put("tid", course.getTid());
			map.put("name", course.getName());
			map.put("jgid", course.getJgid());
			map.put("bname", course.getBname());
			map.put("xq", course.getXq());
		}
		List<Course> courselist= courseMapper.queryCourseByAll(map);
		if(courselist.size()>0){
			return 0;
		}else{
			return courseMapper.updateCourse(course);
		}
	}
	
	public Course queryCourseById(int id) throws Exception {
		return courseMapper.queryCourseById(id);
	}
 
}
